﻿//using System;
//using System.Configuration;
//using System.Data;
//using System.Data.SqlClient;
//using System.Threading;
//using SqlSystemWatcher.Common;

//namespace SqlSystemWatcher.DatabaseFileLog
//{
//    public class DatabaseFileLogger
//    {
//        public void LoggerStarter()
//        {
//            const string sqlCommand = "SELECT * FROM [dbo].[uvwLogCheckInterval] WHERE LogType = 'DatabaseFileLog'";
//            string connectionString = ConfigurationManager.ConnectionStrings["ConStr"].ToString();

//            var ds = new DataSet();

//            try
//            {
//                var sqlConnection = new SqlConnection(connectionString);

//                var sqlDa = new SqlDataAdapter {SelectCommand = new SqlCommand(sqlCommand)};
//                sqlDa.SelectCommand.CommandType = CommandType.Text;
//                sqlDa.SelectCommand.Connection = new SqlConnection(sqlConnection.ConnectionString);

//                sqlDa.SelectCommand.Connection.Open();
//                sqlDa.Fill(ds, "LogCheckInterval");
//                sqlDa.SelectCommand.Connection.Close();
//            }
//            catch (SqlException sqlException)
//            {
//                var customException = new CustomException();
//                customException.WriteInfoScreen(CustomException.InfoScreenLevel.Exception, "DatabaseFileLogger",
//                                                sqlException.GetType().ToString(), sqlException.Message);
//            }
//            catch (Exception exception)
//            {
//                var customException = new CustomException();
//                customException.WriteInfoScreen(CustomException.InfoScreenLevel.Exception, "DatabaseFileLogger",
//                                                exception.GetType().ToString(), exception.Message);
//            }

//            foreach (DataRow instance in ds.Tables["LogCheckInterval"].Rows)
//            {
//                DateTime lastCheckTimeStamp = instance["LastCheck"] != DBNull.Value
//                                                  ? (DateTime) instance["LastCheck"]
//                                                  : DateTime.MinValue;

//                if (lastCheckTimeStamp.AddMinutes((int) instance["CheckInterval"]) > DateTime.Now)
//                    continue;

//                var databaseFileLoggerCore = new DatabaseFileLoggerCore(instance["InstanceName"].ToString());
//                databaseFileLoggerCore.DoIt();
//            }

//            Thread.Sleep(30000);
//        }
//    }
//}

